/*
 * Copyright (C) 2003, Velocityme Partnership
 * DepartmentValueToString.java
 *
 * Created on 30 August 2003, 05:24
 */

package com.velocityme.valueobjects;

import com.velocityme.interfaces.RemoteClientSessionUtil;
import javax.ejb.*;
import java.rmi.RemoteException;
import java.util.Comparator;
import javax.naming.NamingException;

/**
 *
 * @author  Robert Crida Work
 */
public class DepartmentValueToString extends DepartmentValue implements Comparable {
    
    private String qualifiedName = null;
    
    /** Creates a new instance of DepartmentValueToString */
    public DepartmentValueToString(DepartmentValue p_value) {
        super(p_value);
        qualifiedName = p_value.getQualifiedName();
    }
    
    public String toString() {
        if (qualifiedName == null) {
            // This method of getting the qualified name is a terrible hack but short 
            // of rewriting the whole value object manually and also writing a manual
            // method for creating it etc, with the current xdoclet setup I can't figure
            // out any other way to do it!!!
            try {
                qualifiedName = RemoteClientSessionUtil.getHome().create().getDepartmentQualifiedName(getPrimaryKey());
            }
            catch(NamingException e) {
                throw new EJBException(e);
            }
            catch(CreateException e) {
                throw new EJBException(e);
            }
            catch(RemoteException e) {
                throw new EJBException(e);
            }
        }
        return qualifiedName;
    }

    public int compareTo(Object o) {
        return toString().compareTo(o.toString());
    }
    
}
